<template>
  <el-collapse-item title="边框" name="border">
    <el-form label-width="70px">
      <el-form-item label="开关">
        <el-switch v-model="curComponent.borderSW" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>
      <el-form-item label="边框类型">
        <el-select
          ref="borderSelect"
          v-model="curComponent.borderType"
          class="border-select"
          @change="handleBorderType"
        >
          <el-option v-for="item in borderList" :key="item" :value="item">
            <img alt="" style="width: 150px; height: 3px" :src="BORDER_IMG[item].top" />
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="边框速度">
        <el-select v-model="curComponent.borderSpeed">
          <el-option v-for="item in 5" :key="item" :label="`${item}`" :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="边框特效">
        <el-select v-model="curComponent.borderEffect">
          <el-option
            v-for="(item, index) in borderOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-collapse-item>
</template>

<script>
import {
  BorderData,
  borderOptions,
  textAlignOptions,
  borderStyleOptions,
  verticalAlignOptions,
  selectKey,
  optionMap,
  borderTypeOptions,
} from '@/utils/attr'
import { BORDER_IMG } from '@/utils/constant'

export default {
  name: 'BorderAttr',
  data() {
    return {
      optionMap,
      BorderData,
      textAlignOptions,
      borderStyleOptions,
      verticalAlignOptions,
      selectKey,
      borderOptions,
      borderTypeOptions,
      BORDER_IMG,
      borderList: Object.keys(BORDER_IMG),
    }
  },
  computed: {
    curComponent() {
      return this.$store.state.curComponent
    },
  },
  mounted() {
    this.handleBorderType()
  },
  methods: {
    handleBorderType() {
      const inputInner = this.$refs.borderSelect.$el.querySelector('.el-input__inner')
      inputInner.style.backgroundImage = `url(${BORDER_IMG[this.curComponent.borderType].top})`
    },
  },
}
</script>

<style lang="scss" scoped>
.border-select {
  ::v-deep .el-input__inner {
    text-indent: 99999em;
    background-size: 120px 3px;
    background-position: 18px;
    background-repeat: no-repeat;
    color: #fff;
  }
}
</style>
